package com.simon.train.business.controller.admin;


import com.simon.train.business.dto.StationQueryDto;
import com.simon.train.business.dto.StationSaveDto;
import com.simon.train.business.service.StationService;
import com.simon.train.business.vo.StationQueryVO;
import com.simon.train.common.Result.Result;
import com.simon.train.common.vo.PageVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/station")
public class StationAdminController {

    @Resource
    private StationService stationService;

    @PostMapping("/save")
    public Result<Object> SaveStation(@Valid @RequestBody StationSaveDto stationSaveDto){
        stationService.SaveStation(stationSaveDto);
        return new Result<>();
    }

    @GetMapping("/queryList")
    public Result<PageVO<StationQueryVO>> StationQueryList(@Valid StationQueryDto stationQueryDto){
         /**
         * businessId通过线程变量获取 从而不需要由前端传入 保证了效率和安全性
         */
        PageVO<StationQueryVO> lists = stationService.QueryStationList(stationQueryDto);
        return new Result<>(lists);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> DeleteStation(@PathVariable("id") Long id){
        stationService.deleteStation(id);
        return new Result<>();
    }

    /**
     * 查询全部的车站信息
     * @return
     */
    @GetMapping("/queryAll")
    public Result<List<StationQueryVO>> TrainQueryList(){
        List<StationQueryVO> lists = stationService.QueryTrainAll();
        return new Result<>(lists);
    }

}
